package com.mls.web.controller.education;

import java.util.List;

import com.mls.education.domain.EduCourseType;
import com.mls.education.service.IEduCourseTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.mls.common.annotation.Log;
import com.mls.common.enums.BusinessType;
import com.mls.education.domain.EduCourse;
import com.mls.education.service.IEduCourseService;
import com.mls.common.core.controller.BaseController;
import com.mls.common.core.domain.AjaxResult;
import com.mls.common.utils.poi.ExcelUtil;
import com.mls.common.core.page.TableDataInfo;

/**
 * 课程信息Controller
 * 
 * @author admin
 * @date 2022-02-19
 */
@Controller
@RequestMapping("/education/course")
public class EduCourseController extends BaseController
{
    private String prefix = "education/course";

    @Autowired
    private IEduCourseService eduCourseService;

    @Autowired
    private IEduCourseTypeService eduCourseTypeService;

    @RequiresPermissions("education:course:view")
    @GetMapping()
    public String course(ModelMap mmap)
    {
        mmap.put("courseTypeList", eduCourseTypeService.selectEduCourseTypeList(new EduCourseType()));
        mmap.put("courseType", new EduCourseType());
        return prefix + "/course";
    }

    /**
     * 查询课程信息列表
     */
    @RequiresPermissions("education:course:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EduCourse eduCourse)
    {
        startPage();
        List<EduCourse> list = eduCourseService.selectEduCourseList(eduCourse);
        return getDataTable(list);
    }

    /**
     * 导出课程信息列表
     */
    @RequiresPermissions("education:course:export")
    @Log(title = "课程信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EduCourse eduCourse)
    {
        List<EduCourse> list = eduCourseService.selectEduCourseList(eduCourse);
        ExcelUtil<EduCourse> util = new ExcelUtil<EduCourse>(EduCourse.class);
        return util.exportExcel(list, "课程信息数据");
    }

    /**
     * 新增课程信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("courseTypeList", eduCourseTypeService.selectEduCourseTypeList(new EduCourseType()));
        return prefix + "/add";
    }

    /**
     * 新增保存课程信息
     */
    @RequiresPermissions("education:course:add")
    @Log(title = "课程信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EduCourse eduCourse)
    {
        return toAjax(eduCourseService.insertEduCourse(eduCourse));
    }

    /**
     * 修改课程信息
     */
    @RequiresPermissions("education:course:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        EduCourse eduCourse = eduCourseService.selectEduCourseById(id);
        mmap.put("courseTypeList", eduCourseTypeService.selectEduCourseTypeList(new EduCourseType()));
        mmap.put("eduCourse", eduCourse);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程信息
     */
    @RequiresPermissions("education:course:edit")
    @Log(title = "课程信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EduCourse eduCourse)
    {
        return toAjax(eduCourseService.updateEduCourse(eduCourse));
    }

    /**
     * 删除课程信息
     */
    @RequiresPermissions("education:course:remove")
    @Log(title = "课程信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(eduCourseService.deleteEduCourseByIds(ids));
    }

    /**
     * 查询课程详细
     */
    @RequiresPermissions("education:courselession:list")
    @GetMapping("/detail/{courseId}")
    public String detail(@PathVariable("courseId") Integer courseId, ModelMap mmap)
    {
        mmap.put("course",eduCourseService.selectEduCourseById(courseId));
        mmap.put("courseList", eduCourseService.selectEduCourseList(new EduCourse()));
        return "education/courselesson/courselesson";
    }
}
